< previous page page_423 next page >

Page 423
If, on a form, you have a grid that has one SQL statement and a collection of text boxes that has another SQL statement, you need two Data controls. Typically, the code to manage both is duplicated. If the Data control fails for reasons beyond your control, you're stuck until the vendor offers a solution. You can mitigate the risk of code duplication, at least, by passing a reference to the Data control to a common class. However, the better, more scalable and reusable solution is to use ADO, RDO, DAO, VBSQL, ODBC API, or third-party tools such as Oracle Objects for Visual Basic. That way, you can create a common mechanism to handle each platform, encapsulating your application from changes in data access implementation code. Data controls can't optimally offer this kind of scalability. Nonetheless, when you have an independent mechanism in place, there's no harm in using Data controls; you have something to fall back on if the Data control fails.
Modeling the Database Access Object Model
Given that this subsystem is part of the critical path of any application you develop, it's complex. In fact, much of its functionality is so complex that there isn't enough space in this chapter to cover every issue you might face. RDO alone offers more services than both DAO and ADO. Nevertheless, this section explains the key interactions between the objects in this subsystem. Figure 19.2 shows the interactions in a sequence diagram. Because the interactions can be complicated at times, it's useful to use Visual Basic's Call Stack dialog box to verify the sequence of method calls.
Tip
When you create sequence diagrams for complex object interactions, use Visual Basic's Call Stack dialog box to view a list of method invocations. The call stack list isn't always exhaustive, but it's informative. To use it, choose View Call Stack (Ctrl+L) from the Visual Basic menu.

The interaction in Figure 19.2 involves using the ActiveX Data Objects mechanism. The code module modMain has a method, Sub Main, that is the startup method for the application. It invokes the initializeDB method of CDatabaseForm (the class instance: theDatabaseForm). The initializeDB method accepts a Byte argument that contains the Ado value of the following enum:
Public Enum eDataAccess
    Ado
    Dao
    Rdo
End Enum

 
< previous page page_423 next page >

If you like this book, buy it!